package com.link.linkupjavaweb.service.impl;

import com.link.linkupjavaweb.dto.RankDTO;
import com.link.linkupjavaweb.mapper.RankMapper;
import com.link.linkupjavaweb.service.RankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 排行榜Service实现类
 */
@Service
public class RankServiceImpl implements RankService {
    
    @Autowired
    private RankMapper rankMapper;
    
    @Override
    public List<RankDTO> getRankList(Integer limit) {
        if (limit == null || limit <= 0) {
            limit = 100; // 默认显示前100名
        }
        
        List<RankDTO> rankList = rankMapper.selectRankList(limit);
        
        // 手动设置排名（从1开始）
        for (int i = 0; i < rankList.size(); i++) {
            rankList.get(i).setRankPosition(i + 1);
        }
        
        return rankList;
    }
    
    @Override
    public Integer getUserRank(Long userId) {
        return rankMapper.selectUserRank(userId);
    }
}

